package com.ruanyuan.springboot.controller;

import com.ruanyuan.springboot.pojo.Address;
import com.ruanyuan.springboot.pojo.Car;
import com.ruanyuan.springboot.pojo.Employee;
import com.ruanyuan.springboot.service.AddressService;
import com.ruanyuan.springboot.service.EmployeeService;
import com.ruanyuan.springboot.utlis.LayuiPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 用户表控制层
 */
@RequestMapping("/employee")
@Controller
public class EmployeeController {
    @Autowired
    private EmployeeService EmployeeService;
    @Autowired
    private AddressService AddressService;
    /**
     * 转到用户界面
     */
    @RequestMapping("/getemployee")
    public String getto(Model model){
        List<Address> addresses = this.AddressService.seleteAddress();
        model.addAttribute("addresses",addresses);
        return "EmployeeIndex";
    }

    /**
     * 多条件查询个数
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/selectEmployee")
    @ResponseBody
    public LayuiPage<Employee> selectEmployee(int page,int limit){
        int _page = (page-1)*limit;
        List<Employee> employeelist = this.EmployeeService.selectEmployee(_page,limit);
        System.out.println(employeelist);
        int count = this.EmployeeService.selectEmployeeCount();
        return new LayuiPage<>(0, "", count, employeelist);
    }
    /**
     * 添加用户
     */
    @RequestMapping("/insertEmployee")
    @ResponseBody
    public int insertEmployee(Employee employee){
        return this.EmployeeService.insertEmployee(employee);
    }
    /**
     * 修改用户
     */
    @RequestMapping("/updateEmployee")
    @ResponseBody
    public int updateEmployee(Employee employee){
        return this.EmployeeService.updateEmployee(employee);
    }
    /**
     * 单个删除用户信息
     */
    @RequestMapping("/deleteEmployee")
    @ResponseBody
    public int deleteEmployee(String id){
        return this.EmployeeService.deleteEmployeeById(id);
    }
    /**
     * 批量删除用户信息
     */
    @RequestMapping("/deletesEmployee")
    @ResponseBody
    public int deletesEmployee(String[] empids){
        return this.EmployeeService.deleteEmployeeIds(empids);
    }
}
